import java.util.Scanner;


public class ManageAccount {
	private Scanner sc = new Scanner(System.in);
	public ManageAccount()
	{
		
	}
	
	public void checkLogging()
	{
		int i;
		if (MovieApp.loggedIn==false)
		{
			System.out.println("Enter your account : ");
			String account = sc.next().trim().toLowerCase();
			System.out.println("Enter your password: ");
			String password = sc.next().trim().toLowerCase();
			for (i=0; i<MovieApp.staffList.size();i++)
			{
				if (MovieApp.staffList.get(i).getStaffAccount().trim().toLowerCase().equals(account))
					if (MovieApp.staffList.get(i).getStaffPassword().trim().toLowerCase().equals(password))
					{
						System.out.println("Welcome !");
						MovieApp.loggedIn = true;
						configure();
						break;
					}
					else
					{
						System.out.println("Wrong PassWord!");
						checkLogging();
					}
			if (i ==MovieApp.staffList.size())
			{
				System.out.println("Account doesnt exist!");
				checkLogging();
			}
			}
			
		}
		else 
			configure();
	}
	
	public void configure()
	{
		
		int choice;  
    	do { 
    		System.out.println("1. Configure day setting.");
    		System.out.println("2. Configure movie setting.");
    		System.out.println("3. Configure Show setting.");
    		System.out.println("4. Configure price setting.");
			System.out.println("5:  Log out "); 
			choice = sc.nextInt(); 
 
	switch (choice) { 
	    case 1: 
	    		System.out.println("1. Weekday");
	    		System.out.println("2. Weekend");
	    		System.out.println("3. Public holiday");
	    		System.out.println("Enter your choice: ");
	    		MovieApp.dayClass = sc.nextInt()-1;
	    		
	            break; 
	    case 2: 
	    		updateMovie();
	    		break;
	    case 3:   
	    		updateShow();
	    		break;
	    case 4: 
	    		System.out.println("Enter the default price: ");
	    		MovieApp.price= sc.nextDouble();
	    		break;
	    case 5: 
	    	MovieApp.loggedIn=false;
	    	break;
	    default:
	    	MovieApp.loggedIn=false;
	    	break;
	}  
	} while (choice < 5); 
	}
	
	
	public void updateMovie()
	{
		
		int choice;  
    	do { 
    		System.out.println("1. Update Movie");
    		System.out.println("2. Add new Movie");
    		System.out.println("3. Remove Movie");
    		System.out.println("4. Exit");
			choice = sc.nextInt(); 
 
	switch (choice) { 
	    case 1: 
	    		for (int i=0; i<MovieApp.movieList.size();i++)
	    		{
	    			System.out.println("Movie ID  : "+(i+1));
					System.out.println("Movie name: "+MovieApp.movieList.get(i).getMovieName());
					System.out.println("Movie Class: "+MovieApp.movieList.get(i).getMovieClass());
					System.out.println("Movie Type: "+MovieApp.movieList.get(i).getMovieType());
					System.out.println("Movie Status: "+MovieApp.movieStatus[MovieApp.movieList.get(i).getStatus()]);
					System.out.println();
	    		}
	    		System.out.println("Enter your MovieID to update: ");
	    		int choiceOfMovie = sc.nextInt()-1;
	    		for (int i=0;i < MovieApp.movieStatus.length;i++)
	    		{
	    			System.out.println("Movie Status ID "+(i+1));
	    			System.out.println(MovieApp.movieStatus[i]);
	    		}
	    		System.out.println("Choose Movie Status: ");
	    		int choiceOfStatus = sc.nextInt()-1;
	    		MovieApp.movieList.get(choiceOfMovie).setMovieStatus(choiceOfStatus);
	    		for (int i=0;i < MovieApp.movieClass.length;i++)
	    		{
	    			System.out.println("Movie Class ID "+(i+1));
	    			System.out.println(MovieApp.movieClass[i]);
	    		}
	    		System.out.println("Choose Movie Class: ");
	    		int choiceOfClass = sc.nextInt()-1;
	    		MovieApp.movieList.get(choiceOfMovie).setMovieClass(choiceOfClass);
	            break; 
	    case 2: 
	    		MovieItem temp = new MovieItem();
	    		System.out.println("Enter your Movie name: ");
	    		String name = sc.next();
	    		System.out.println("Enter your Movie type: ");
	    		String type = sc.next();
	    		for (int i=0;i < MovieApp.movieStatus.length;i++)
	    		{
	    			System.out.println("Movie Status ID "+(i+1));
	    			System.out.println(MovieApp.movieStatus[i]);
	    		}
	    		System.out.println("Choose Movie Status: ");
	    		choiceOfStatus = sc.nextInt()-1;

	    		for (int i=0;i < MovieApp.movieClass.length;i++)
	    		{
	    			System.out.println("Movie Class ID "+(i+1));
	    			System.out.println(MovieApp.movieClass[i]);
	    		}
	    		System.out.println("Choose Movie Class: ");
	    		choiceOfClass = sc.nextInt()-1;
	    		
	    		temp.setMovieClass(choiceOfClass);
	    		temp.setMovieName(name);
	    		temp.setMovieStatus(choiceOfStatus);
	    		temp.setMovieType(type);
	    		MovieApp.movieList.add(temp);
	    		break;
	    case 3:   
		    	for (int i=0; i<MovieApp.movieList.size();i++)
	    		{
	    			System.out.println("Movie ID  : "+(i+1));
					System.out.println("Movie name: "+MovieApp.movieList.get(i).getMovieName());
					System.out.println("Movie Class: "+MovieApp.movieList.get(i).getMovieClass());
					System.out.println("Movie Type: "+MovieApp.movieList.get(i).getMovieType());
					System.out.println("Movie Status: "+MovieApp.movieStatus[MovieApp.movieList.get(i).getStatus()]);
					System.out.println();
	    		}
		    	System.out.println("Enter your MovieID to remove: ");
	    		choiceOfMovie = sc.nextInt()-1;
	    		MovieApp.movieList.remove(choiceOfMovie);
	    		break;
	    default:
	    	break;
	}  
	} while (choice < 4); 
	}
	
	public void updateShow()
	{
		int choice;  
    	do { 
    		System.out.println("1. Update Show");
    		System.out.println("2. Add new Show");
    		System.out.println("3. Remove Show");
    		System.out.println("4. Exit");
			choice = sc.nextInt(); 
 
	switch (choice) { 
	    case 1: 
		    	for (int i=0;i < MovieApp.cineplexList.size();i++)
					System.out.println(i+1+" " +MovieApp.cineplexList.get(i).getCineplexName());
				System.out.println("Enter your choice of Cinema: ");
				int choiceOfCinema = sc.nextInt()-1;
				for (int i=0; i< MovieApp.cineplexList.get(choiceOfCinema).getShowList().size();i++)
					{	
						System.out.println("Show ID     : "+(i+1));
						System.out.println("Movie Name  : "+MovieApp.cineplexList.get(choiceOfCinema).getShowList().get(i).getMovieName());
						System.out.println("Show time   : "+MovieApp.cineplexList.get(choiceOfCinema).getShowList().get(i).getTime());
						System.out.println("Cinema      : "+MovieApp.cineplexList.get(choiceOfCinema).getShowList().get(i).getCineplex());
						System.out.println("Hall        : "+MovieApp.cineplexList.get(choiceOfCinema).getShowList().get(i).getCinemaItem().getCinemaName());
					}
				System.out.println("Enter show ID: ");
				int choiceOfShow = sc.nextInt()-1;
				
	            break; 
	    case 2: 
	    		ShowItem temp = new ShowItem();
	    		for (int i=0; i<MovieApp.cineplexList.size();i++)
	    			System.out.println((i+1)+" " +MovieApp.cineplexList.get(i).getCineplexName());
	    		System.out.println("Enter Cinema ID: ");
	    		choiceOfCinema = sc.nextInt()-1;
	    		for (int i=0; i<MovieApp.movieList.size();i++)
	    		{
	    			System.out.println("Movie ID  : "+(i+1));
					System.out.println("Movie name: "+MovieApp.movieList.get(i).getMovieName());
					System.out.println("Movie Class: "+MovieApp.movieList.get(i).getMovieClass());
					System.out.println("Movie Type: "+MovieApp.movieList.get(i).getMovieType());
					System.out.println("Movie Status: "+MovieApp.movieStatus[MovieApp.movieList.get(i).getStatus()]);
					System.out.println();
	    		}
	    		System.out.println("Enter your MovieID to show in: ");
	    		int choiceOfMovie = sc.nextInt()-1;
	    		sc.nextLine();
	    		System.out.println("Enter hall: ");
	    		String hall= sc.nextLine();
	    		System.out.println("Enter Date: ");
	    		String date= sc.nextLine();
	    		
	    		temp.setCineplex(MovieApp.cineplexList.get(choiceOfCinema).getCineplexName());
	    		temp.getCinemaItem().setCinemaName(hall);
	    		temp.setMovieItem(MovieApp.movieList.get(choiceOfMovie));
	    		temp.setTime(date);
	    		MovieApp.cineplexList.get(choiceOfCinema).getShowList().add(temp);
	    		break;
	    case 3:   
	    	for (int i=0;i < MovieApp.cineplexList.size();i++)
				System.out.println(i+1+" " +MovieApp.cineplexList.get(i).getCineplexName());
			System.out.println("Enter your choice of Cinema: ");
			choiceOfCinema = sc.nextInt()-1;
	    	for (int i=0; i< MovieApp.cineplexList.get(choiceOfCinema).getShowList().size();i++)
			{	
				System.out.println("Show ID     : "+(i+1));
				System.out.println("Movie Name  : "+MovieApp.cineplexList.get(choiceOfCinema).getShowList().get(i).getMovieName());
				System.out.println("Show time   : "+MovieApp.cineplexList.get(choiceOfCinema).getShowList().get(i).getTime());
				System.out.println("Cinema      : "+MovieApp.cineplexList.get(choiceOfCinema).getShowList().get(i).getCineplex());
				System.out.println("Hall        : "+MovieApp.cineplexList.get(choiceOfCinema).getShowList().get(i).getCinemaItem().getCinemaName());
			}
	    		System.out.println("Enter show ID: ");
	    		choiceOfShow = sc.nextInt()-1;
	    		MovieApp.cineplexList.get(choiceOfCinema).getShowList().remove(choiceOfShow);
	    		break;
	    default:
	    	break;
	}  
	} while (choice < 4); 
	}
}
